<template>
    <z-paging :use-virtual-list="true" :auto-show-back-to-top="true" :loading-full-fixed="true"
        :auto-show-system-loading="true" ref="pagingRef" @query="queryListFn">
        <template #cell="{ item, index }">
            <!-- 循环列表 写你的单个布局 item 就是循环的每一项 -->
            <lh-list-item :title="item.Name" :no="item.Tybh" noTitle='统一编号'
                :address="item.District + item.Town + item.Village + '村' + (item.Hamlet || '') + '组'"
                @routerTo="routerTo(item)" @openNavigationPopup="openNavigationPopup(item)">
                <template #tags>
                    <uv-tags size="mini" shape="circle" type="primary" bgColor="#c7c346" borderColor="#c7c346" text="县级"
                        style="margin-right: 10rpx"></uv-tags>
                    <uv-tags size="mini" shape="circle" style="margin-right: 10rpx" type="primary" bgColor="#c7c346"
                        borderColor="#c7c346" :text="item.Gmdj"></uv-tags>
                    <uv-tags size="mini" shape="circle" type="primary" bgColor="#2e5bef" borderColor="#2e5bef"
                        :text="getYhdTypeName(item.TypeCode)"></uv-tags>
                </template>
            </lh-list-item>
        </template>
        <template #empty>
            <uv-empty mode="list" marginTop="0rpx" iconSize="180" textSize="28"></uv-empty>
        </template>
    </z-paging>
    <!-- 选择导航应用 -->
    <lh-navigation-popup v-model="navigationPopup" :longitude="selectedLongitude" :latitude="selectedLatitude"
        :addressName="addressName" />
</template>

<script lang="ts" setup>
import { GetPageYhd_API } from '@/server/home'
import { getYhdTypeName } from '@/utils/util'
let adcode = undefined
onLoad((e) => {
    adcode = e.adcode
})

const pagingRef = ref()
/**
 * 获取数据
 * @param pageNo 当前页
 * @param pageSize 条数
 */
const queryListFn = async (pageNo: any, pageSize: any) => {
    const params = {
        pageNumber: pageNo,
        pageSize: pageSize,
        AdminCode: adcode,
    }
    try {
        const res = await GetPageYhd_API(params)
        if (res.IsSuccess) {
            pagingRef.value.complete(res.Data.Data)
        }
    } catch (error) {
        pagingRef.value.complete(false)
    }
}
const routerTo = (item) => {
    uni.navigateTo({
        url: `/pages/home/basic/dangerBasic?code=${item.Tybh}`,
    })
}

const navigationPopup = ref(false)
const selectedLongitude = ref(0)
const selectedLatitude = ref(0)
const addressName = ref("")
const openNavigationPopup = (item) => {
    selectedLongitude.value = +item.Lon
    selectedLatitude.value = +item.Lat
    addressName.value = item.Name
    navigationPopup.value = true
}
</script>

<style lang="scss" scoped></style>
